package cmd

import (
	"fmt"
	"twwch/k8s-admin/apis"
	"twwch/k8s-admin/component/repo"
	"twwch/k8s-admin/config"

	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

func init() {
	viper.SetConfigName("config")
	viper.AddConfigPath("./config")
}
func initConfigFile() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	}
}

var preRun = func(cmd *cobra.Command, args []string) {
	initConfigFile()
	var err error
	if conf, err = config.Load(""); err != nil {
		panic(fmt.Errorf("config load failed: %s", err.Error()))
	}

	apis.Init()
	repo.Init()
}
